<template>
  <div>
    <div style="margin-top: 1rem">
      <el-button icon="el-icon-document-add" type="primary" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="Id" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.Id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文章类型" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 对话框 -->
    <el-dialog title="文章类型" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="文章类型名称" :label-width="formLabelWidth">
          <el-input
            v-model="form.articleTypename"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 分页 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pager.pageIndex"
        :page-size="pager.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pager.rowsTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogFormVisible: false,
      pager: {
        pageIndex: 1,
        pageSize: 10,
        rowsTotal: 30,
      },
      tableData: [
        {
          Id: "1",
          name: "新闻时事",
        },
        {
          Id: "2",
          name: "公司动态",
        },
        {
          Id: "3",
          name: "大神风采",
        },
        {
          Id: "4",
          name: "关于我们",
        },
      ],
      form: {
        id: 0,
        articleTypename: "",
      },
      formLabelWidth: "120px",
      //当前下标
      nowIndex: 0,
    };
  },
  methods: {
    //编辑
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      this.form.id = row.id;
      this.form.articleTypename = row.name;
      //获取下标
      this.nowIndex = index;
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    //添加
    handleAdd() {
      this.dialogFormVisible = true;
      this.form.articleTypename = "";
    },
    //确认
    confirm() {},
    //大小更改(分页)
    handleSizeChange(val) {
      console.log(val);
    },
    //当前更改(分页)
    handleCurrentChange(val) {
      console.log(val);
    },
  },
};
</script>

<style>
</style>